package com.smsc.headend.task.engine.handler.impl.collection.builder;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.smsc.headend.module.data.entity.RdScheduleReadParamValue;
import com.smsc.headend.module.protocol.DeviceData;
import com.smsc.headend.module.task.dto.AtomicTask;
import com.smsc.headend.module.task.dto.Task;
import com.smsc.headend.task.engine.exception.UDISTaskExecutorException;
import com.smsc.headend.task.engine.exception.UDISTaskHandlerException;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public interface ScheduleReadBuilder {
    void handleScheduleReadResult(Task task, AtomicTask atomicTask, DeviceData deviceData, String actionResult, Boolean dcuDataItemFlag, Map<String, Object> param) throws UDISTaskExecutorException, UDISTaskHandlerException;

    default String getSuggest(String referValue,String deviceValue) {
        if(StrUtil.isEmpty(referValue)) {
            return null;
        }
        if(referValue.contains("or")) {
            String[] referValues = referValue.trim().split("or");
            List<String> referValueList = Arrays.asList(referValues);
            referValueList = referValueList.stream().map(e->e.trim()).collect(Collectors.toList());
            return referValueList.contains(deviceValue)?RdScheduleReadParamValue.SuggestResultEnum.NORMAL.getCode():RdScheduleReadParamValue.SuggestResultEnum.ABNORMAL.getCode();
        } else {
            return referValue.equals(deviceValue)?RdScheduleReadParamValue.SuggestResultEnum.NORMAL.getCode():RdScheduleReadParamValue.SuggestResultEnum.ABNORMAL.getCode();
        }
    }
}
